<template>
  <div class="logininput">
    <el-form label-width="70px" :rules="rules" :model="account" ref="formRef">
      <el-form-item label="账号" prop="name">
        <el-input class="test" v-model="account.name" />
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="account.password" show-password />
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, ref } from 'vue'
import { useStore } from 'vuex'
import { ElForm } from 'element-plus'
import { rules } from '../config/account-config'
import LocalCache from '@/utils/cache'

export default defineComponent({
  setup() {
    const store = useStore()
    const account = reactive({
      name: LocalCache.getCache('name') ?? '',
      password: LocalCache.getCache('password') ?? ''
    })
    const loginAcction = (ispassword: boolean) => {
      formRef.value?.validate((valid) => {
        if (valid) {
          if (ispassword) {
            LocalCache.setCache('name', account.name)
            LocalCache.setCache('password', account.password)
          } else {
            LocalCache.deleteCache('name')
            LocalCache.deleteCache('password')
          }
          store.dispatch('login/accountLoginAcction', { ...account })
        }
      })
    }
    const formRef = ref<InstanceType<typeof ElForm>>()
    return {
      account,
      rules,
      loginAcction,
      formRef
    }
  }
})
</script>
<style lang="less">
.el-form-item__label {
  font-size: mini;
  color: black;
  font-style: initial;
  font-weight: 600;
}

.el-input__inner {
  background-color: rgba(0, 0, 0, 0.3); //红色
  color: black;
  border-color: orange;
  box-shadow: 0 0 10px 2px rgb(241, 191, 97);
  border-width: 1.5px;
}
</style>
